package mysale.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author SnakeWoodMan
 * @create 2020-12-24 14:49
 */
public class JDBCUtil {

    //定义一个连接对象

    public static Connection getConnection(){
        //加载驱动
        Connection con = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            if (con==null) {
                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/foodsale?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&reqriteBatchedStatements=true&allowPublicKeyRetrieval=true", "root", "123456");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return con;
    }

    public static void close(Connection con){
        if(con!=null){
            try {
                con.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }

}
